all files / circularProgress/ circularProgress.vue

38.89% Statements 7/18
100% Branches 4/4
14.29% Functions 1/7
25% Lines 3/12
1 branch Ignored     
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87                                1× 1×                                                                                                                                          
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
 
import circular from '../internal/circular'
import {getColor} from '../utils'
export default {
  name: 'mu-circular-progress',
  props: {
    max: {
      type: Number,
      default: 100
    },
    min: {
      type: Number,
      default: 0
    },
    mode: {
      type: String,
      default: 'indeterminate',
      validator (val) {
        return ['indeterminate', 'determinate'].indexOf(val) !== -1
      }
    },
    value: {
      type: Number,
      default: 0
    },
    color: {
      type: String
    },
    size: {
      type: Number,
      default: 24
    },
    strokeWidth: {
      type: Number,
      default: 3
    }
  },
  computed: {
    radius () {
      return (this.size - this.strokeWidth) / 2
    },
    circularSvgStyle () {
      return {
        width: this.size,
        height: this.size
      }
    },
    circularPathStyle () {
      const relVal = this.getRelativeValue()
      return {
        stroke: getColor(this.color),
        'stroke-dasharray': `${this.getArcLength(relVal)}, ${this.getArcLength(1)}`
      }
    }
  },
  methods: {
    // material ui 两个计算方法
    getArcLength (fraction) {
      return fraction * Math.PI * (this.size - this.strokeWidth)
    },
    getRelativeValue () {
      const {value, min, max} = this
      const clampedValue = Math.min(Math.max(min, value), max)
      return clampedValue / (max - min)
    }
  },
  components: {
    circular
  }
}